package com.example.www.jiguvideo.app.controller;

import com.example.www.jiguvideo.app.domain.VideoInfoVo;
import com.example.www.jiguvideo.app.domain.VideoAllVo;
import com.example.www.jiguvideo.module.entity.Video;
import com.example.www.jiguvideo.module.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;


    @RequestMapping("/video/info")
    public VideoInfoVo videoInfo(@RequestParam(name = "videoId") BigInteger videoId) {

        Video video = videoService.getVideoInfoById(videoId);

        VideoInfoVo videoInfoVo = new VideoInfoVo();

        List<String> picturesList = Arrays.asList(video.getPictures().split("\\$"));

        videoInfoVo.setPictures(picturesList);
        videoInfoVo.setImage(video.getImage());
        videoInfoVo.setName(video.getName());
        videoInfoVo.setActor(video.getActor());
        videoInfoVo.setParticular(video.getParticular());
        videoInfoVo.setPhoto(video.getPhoto());

        return videoInfoVo;

    }

    @RequestMapping("/video/all")
    public List<VideoAllVo> videoAll() {
        // 调用服务层方法获取所有视频信息
        List<Video> videos = videoService.getAllVideoInfo();

        List<VideoAllVo> videoAllVos = new ArrayList<>();

        for (Video video : videos) {
            VideoAllVo videoAllVo = new VideoAllVo();
            videoAllVo.setId(video.getId());
            videoAllVo.setName(video.getName());
            videoAllVo.setImage(video.getImage());
            videoAllVo.setIntroduce(video.getIntroduce());
            videoAllVos.add(videoAllVo);
        }

        return videoAllVos;
    }
}

